package com.chengzzz.czsee.core

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.StaggeredGridLayoutManager
import com.bumptech.glide.Glide
import com.chengzzz.czsee.R
import com.chengzzz.czsee.adapter.playAdapter
import com.chengzzz.czsee.adapter.videoAdapter
import com.chengzzz.czsee.pojo.DataClass
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.recyclelayout.*
import kotlinx.android.synthetic.main.videoinfo_fragment.*

class infoActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.videoinfo_fragment)

        val data = intent.getParcelableExtra<DataClass.DataBean>("data")
        Glide.with(this).load(data?.vod_pic).into(imageView2)
        textView7.text = data?.vod_content
        textView8.text = data?.vod_name
        textView9.text = data?.vod_director
        textView10.text = data?.vod_actor
        textView11.text = data?.vod_area
        textView12.text = data?.vod_language
        textView13.text = data?.vod_year
        textView14.text = data?.list_name
        textView15.text = data?.vod_continu

       val list: String? =  data?.vod_url
        val mlist = list?.split("$$$")
        lateinit var m3u8list : List<String>
        lateinit var zdlist : List<String>
//        Log.d("list", "onCreate: "+list)
//        Log.d("zdlist", "onCreate: "+zdlist)
//        Log.d("m3u8list", "onCreate: "+m3u8list)
//        if (){  = list?.split("$$$")?.get(1)?.split("\n")
//            .last()  = list?.split("$$$")?.get(0)?.split("\n")
//        }
        if (list?.split("$$$")?.get(0)?.split("\n")?.get(0).toString().indexOf("m3u8")==-1){
            m3u8list= list?.split("$$$")?.get(1)?.split("\n")!!
            zdlist = list?.split("$$$")?.get(0)?.split("\n")
        }else{
            zdlist  = list?.split("$$$")?.get(1)?.split("\n")!!
            m3u8list = list?.split("$$$")?.get(0)?.split("\n")
        }

//        Log.d("mlist", "onCreate: "+ m3u8list?.get(0))
//        Log.d("mlist", "onCreate: "+ m3u8list?.get(0).toString().indexOf("m3u8"))
//        Log.d("mlist", "onCreate: "+mlist)
//
//        Log.d("zdlist", "onCreate: "+zdlist)
//        Log.d("m3u8list", "onCreate: "+m3u8list)
//
//        val layoutManager =
//            LinearLayoutManager(applicationContext)
//        layoutManager.orientation = LinearLayoutManager.HORIZONTAL
        val layoutManager =
            StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL)
        playRecyclerView.layoutManager = layoutManager
        val adapter = playAdapter(m3u8list,data?.vod_name)
        playRecyclerView.adapter = adapter
    }
}
